package com.komodo.island.gdx.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.komodo.island.gdx.KomodoIsland;

public class SplashScreen extends Screen {

	private TextureRegion[] splashLogo;
	private int page = 1;

	private double startTime;
	private double currTime;

	private int deltaTime = 1000;

	private final static int MAX_PAGE = 3;

	@Override
	public void init(KomodoIsland komodoIsland, Texture texture) {
		// TODO Auto-generated method stub
		super.init(komodoIsland, texture);
		screenState = RUNNING;
		splashLogo = new TextureRegion[3];
		splashLogo[0] = new TextureRegion(texture, 0, 0, 480, 320);
		splashLogo[1] = new TextureRegion(texture, 480 ,0,
				480, 320);
		splashLogo[2] = new TextureRegion(komodoIsland.additionTexture, 0,440,
				480, 320);
		
		
	}

	@Override
	public void onScreenRun() {
		// TODO Auto-generated method stub
		// batch.disableBlending();

//		System.out.println("splash");
		currTime = System.currentTimeMillis();
		batch.disableBlending();
		batch.begin();
		try {
			batch.draw(splashLogo[page - 1], 0, 0);
		} catch (Exception e) {

		}

		batch.end();
		batch.enableBlending();
		if (Gdx.input.justTouched()) {
			nextPage();
		}

		if (currTime - startTime >= deltaTime) {
			nextPage();
			startTime = currTime;
		}

	}

	@Override
	public void onScreenLoading() {
		// TODO Auto-generated method stub

	}

	public void nextPage() {
		if (page < MAX_PAGE) {
			page++;

		} else {
			komodoIsland.setScreen(komodoIsland.mainMenuScreen);
			dispose();
		}
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
//		System.out.println("show splash");
		
		startTime = System.currentTimeMillis();
		
	}

}
